package main

import (
	"os"
	"bufio"
	"log"
	"fmt"
)

func main() {
	counts := make(map[string]int)

	files := os.Args[1:]

	if len(files) == 0 {
		countLines(os.Stdin,counts)
	} else {
		for _,arg := range files {
			f,err := os.Open(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr,"%v\n",err)
				continue
			}
			countLines(f,counts)
			f.Close()
		}
	}

	for k,v :=range counts {
		log.Println(k,"--",v)
	}
}

func countLines(f *os.File,counts map[string]int) {
	input := bufio.NewScanner(f)
	for input.Scan() {
		if input.Text() == "n" {
			break
		}
		counts[input.Text()]++
	}
}
